﻿using Ln.Fram.SqlSugarCore.Abstractions;
using Ln.Rbac.Domain.Entities;
using Ln.Rbac.Domain.Shared.Enums;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;

namespace Ln.Rbac.SqlSugarCore.DataSeeds;

public class MenuPureDataSeed : IDataSeedContributor, ITransientDependency
{
	#region 构造函数
	public MenuPureDataSeed(ISqlSugarRepository<MenuAggregateRoot> repository, IGuidGenerator guidGenerator) => (_repository, _guidGenerator) = (repository, guidGenerator);
	#endregion

	#region 成员属性
	private ISqlSugarRepository<MenuAggregateRoot> _repository;
	private IGuidGenerator _guidGenerator;
	#endregion

	#region 自身方法
	public async Task SeedAsync(DataSeedContext context) { if (!await _repository.IsAnyAsync(x => x.MenuName == "系统管理" && x.MenuSource == MenuSourceEnum.Pure)) await _repository.InsertManyAsync(GetSeedData()); }

	private List<MenuAggregateRoot> GetSeedData()
	{
		List<MenuAggregateRoot> entities = new List<MenuAggregateRoot>();
		Guid systemId = _guidGenerator.Create();
		Guid monitorId = _guidGenerator.Create();
		Guid userId = _guidGenerator.Create();
		Guid roleId = _guidGenerator.Create();
		Guid menuId = _guidGenerator.Create();
		Guid deptId = _guidGenerator.Create();
		Guid postId = _guidGenerator.Create();
		Guid operId = _guidGenerator.Create();
		Guid logsId = _guidGenerator.Create();
		entities.AddRange([
			new(systemId, Guid.Empty) { MenuName = "系统管理", MenuType = MenuTypeEnum.Catalogue, Router = "/system", MenuIcon = "ri:settings-3-line", OrderNum = 100 },
			new(monitorId, Guid.Empty) { MenuName = "系统监控", MenuType = MenuTypeEnum.Catalogue, Router = "/monitor", MenuIcon = "ep:monitor", OrderNum = 99 },
			new(_guidGenerator.Create(), monitorId) { MenuName = "在线用户", PermissionCode = "monitor:online:list", MenuType = MenuTypeEnum.Menu, Router = "/monitor/online-user", MenuIcon = "ri:user-voice-line", OrderNum = 100, RouterName = "OnlineUser", Component = "monitor/online/index" },
			new(userId, systemId) { MenuName = "用户管理", PermissionCode = "system:user:list", MenuType = MenuTypeEnum.Menu, Router = "/system/user/index", MenuIcon = "ri:admin-line", OrderNum = 100, RouterName = "SystemUser" },
			new(_guidGenerator.Create(), userId) { MenuName = "用户查询", PermissionCode = "system:user:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), userId) { MenuName = "用户新增", PermissionCode = "system:user:add", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), userId) { MenuName = "用户修改", PermissionCode = "system:user:edit", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), userId) { MenuName = "用户删除", PermissionCode = "system:user:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), userId) { MenuName = "重置密码", PermissionCode = "system:user:resetPwd", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(roleId, systemId) { MenuName = "角色管理", PermissionCode = "system:role:list", MenuType = MenuTypeEnum.Menu, Router = "/system/role/index", MenuIcon = "ri:admin-fill", OrderNum = 99, RouterName = "SystemRole" },
			new(_guidGenerator.Create(), roleId) { MenuName = "角色查询", PermissionCode = "system:role:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), roleId) { MenuName = "角色新增", PermissionCode = "system:role:add", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), roleId) { MenuName = "角色修改", PermissionCode = "system:role:edit", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), roleId) { MenuName = "角色删除", PermissionCode = "system:role:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(menuId, systemId) { MenuName = "菜单管理", PermissionCode = "system:menu:list", MenuType = MenuTypeEnum.Menu, Router = "/system/menu/index", MenuIcon = "ep:menu", OrderNum = 98, RouterName = "SystemMenu" },
			new(_guidGenerator.Create(), menuId) { MenuName = "菜单查询", PermissionCode = "system:menu:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), menuId) { MenuName = "菜单新增", PermissionCode = "system:menu:add", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), menuId) { MenuName = "菜单修改", PermissionCode = "system:menu:edit", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), menuId) { MenuName = "菜单删除", PermissionCode = "system:menu:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(deptId, systemId) { MenuName = "部门管理", PermissionCode = "system:dept:list", MenuType = MenuTypeEnum.Menu, Router = "/system/dept/index", MenuIcon = "ri:git-branch-line", OrderNum = 97, RouterName = "SystemDept" },
			new(_guidGenerator.Create(), deptId) { MenuName = "部门查询", PermissionCode = "system:dept:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), deptId) { MenuName = "部门新增", PermissionCode = "system:dept:add", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), deptId) { MenuName = "部门修改", PermissionCode = "system:dept:edit", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), deptId) { MenuName = "部门删除", PermissionCode = "system:dept:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(postId, systemId) { MenuName = "岗位管理", PermissionCode = "system:post:list", MenuType = MenuTypeEnum.Menu, Router = "/system/post/index", MenuIcon = "ant-design:deployment-unit-outlined", OrderNum = 96, RouterName = "SystemPost" },
			new(_guidGenerator.Create(), postId) { MenuName = "岗位查询", PermissionCode = "system:post:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), postId) { MenuName = "岗位新增", PermissionCode = "system:post:add", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), postId) { MenuName = "岗位修改", PermissionCode = "system:post:edit", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), postId) { MenuName = "岗位删除", PermissionCode = "system:post:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(operId, monitorId) { MenuName = "操作日志", PermissionCode = "monitor:operlog:list", MenuType = MenuTypeEnum.Menu, Router = "/monitor/operation-logs", MenuIcon = "ri:history-fill", OrderNum = 100, RouterName = "OperationLog", Component = "monitor/logs/operation/index" },
			new(_guidGenerator.Create(), operId) { MenuName = "操作查询", PermissionCode = "monitor:operlog:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), operId) { MenuName = "操作删除", PermissionCode = "monitor:operlog:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(logsId, monitorId) { MenuName = "登录日志", PermissionCode = "monitor:logininfor:list", MenuType = MenuTypeEnum.Menu, Router = "/monitor/login-logs", IsShow = true, IsLink = false, IsCache = true, Component = "monitor/logs/login/index", MenuIcon = "ri:window-line", OrderNum = 100, RouterName = "LoginLog", },
			new(_guidGenerator.Create(), logsId) { MenuName = "登录查询", PermissionCode = "monitor:logininfor:query", MenuType = MenuTypeEnum.Component, OrderNum = 100 },
			new(_guidGenerator.Create(), logsId) { MenuName = "登录删除", PermissionCode = "monitor:logininfor:remove", MenuType = MenuTypeEnum.Component, OrderNum = 100, },
		]);
		entities.ForEach(m =>
		{
			m.IsDeleted = false;
			m.State = true;
			m.MenuSource = MenuSourceEnum.Pure;
			m.IsShow = true;
		});
		return entities;
	}
	#endregion
}
